const MyPromise = require('./myPromise');

const p1 = new MyPromise((resolve, reject) => {
    setTimeout(() => {
        resolve('成功');
    }, 2000);
    // throw new Error('这是 throw 的error');
    // resolve('成功');
    // reject('失败');
});

const p2 = function () {
    return new MyPromise((resolve, reject) => {
        // setTimeout(() => {
        //     resolve('成功');
        // }, 2000);
        // throw new Error('这是 throw 的error');
        // resolve(' p2 成功');
        reject(' p2 失败');
    });
}

// const allPro = MyPromise.all(['a', 'b', 'c', p1]);
// allPro.then(value => {
//     console.log('value - all', value);
// });

// MyPromise.resolve(100).then(value => {
//     console.log('100', value);
// });

// MyPromise.resolve(p2()).then(value => {
//     console.log('p2', value);
// });

// p2().finally(() => {
//     console.log('finally');
//     return p1;
// }).then(value => {
//     console.log('value', value);
// }, reason => {
//     console.log('reason', reason);
// });

p2().then(value => {
    console.log('value', value);
}).catch(reason => {
    console.log('reason', reason);
});

